/*
 * Copyright (c) 2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SAMPLE_BITMAP_H
#define SAMPLE_BITMAP_H
#include <ace/xcomponent/native_interface_xcomponent.h>
#include <arpa/nameser.h>
#include <bits/alltypes.h>
#include <native_window/external_window.h>
#include <native_drawing/drawing_bitmap.h>
#include <native_drawing/drawing_color.h>
#include <native_drawing/drawing_canvas.h>
#include <native_drawing/drawing_pen.h>
#include <native_drawing/drawing_brush.h>
#include <native_drawing/drawing_path.h>
#include <cstdint>
#include <map>
#include <sys/mman.h>
#include <string>
#include "napi/native_api.h"

class PluginRender {
public:
    PluginRender() = default;
    ~PluginRender();
    static napi_value NapiDrawPage(napi_env env, napi_callback_info info);
    static PluginRender *GetInstance(OH_NativeXComponent *component);
    static void Release(OH_NativeXComponent *component);
    void DrawPath(OH_Drawing_Path *pathB);
    void SetNativeWindow(OHNativeWindow *nativeWindow);
    void Prepare();
    void Create();
    void DisPlay();
    void ConstructPathDefault();
    void ConstructPathAFromTop();
    void ConstructPathAFromBottom();
    void ConstructPathB();
    void ConstructPathC();
    void SetPenAndBrush();
    void Export(napi_env env, napi_value exports);
    void RegisterCallback(OH_NativeXComponent *nativeXComponent);
    void Destroy();
    void EmulateInit();
    void InitData(int flipType, int positionX, int positionY, int drawPosition, int drawState);
    
public:
    OH_NativeXComponent_Callback renderCallback_;

    OH_Drawing_Bitmap *cBitmap_ = nullptr;
    OH_Drawing_Canvas *cCanvas_ = nullptr;

    OH_Drawing_Path *cPathA_ = nullptr;
    OH_Drawing_Path *cPathB_ = nullptr;
    OH_Drawing_Path *cPathC_ = nullptr;
    OH_Drawing_Brush *cBrushA_ = nullptr;
    OH_Drawing_Brush *cBrushB_ = nullptr;
    OH_Drawing_Brush *cBrushC_ = nullptr;
    OH_Drawing_Pen *cPenA_ = nullptr;
    OH_Drawing_Pen *cPenB_ = nullptr;
    OH_Drawing_Pen *cPenC_ = nullptr;
    OH_Drawing_Rect *cRect_ = nullptr;
    OHNativeWindow *nativeWindow_ = nullptr;
    uint32_t *mappedAddr_ = nullptr;
    BufferHandle *bufferHandle_ = nullptr;
    struct NativeWindowBuffer *buffer_ = nullptr;
    int fenceFd_ = 0;
    int flipType_ = 0;
    int positionX_ = 0;
    int positionY_ = 0;
    int drawPosition_ = 0;
    int drawState_ = 0;
};

#endif
